//
//  YZHGMyViewController.m
//  AnXin100
//
//  Created by 王合润 on 2018/9/17.
//  Copyright © 2018年 tzhg. All rights reserved.
//

#import "TZHGMyViewController.h"
#import "UIView+SDAutoLayout.h"
#import "ZXCategories.h"
#import "Header.h"
//私人定制
#import "AXAXMyMenuTableViewCell.h"
//专家的
#import "WHRPrivateOrderCell.h"
#import "AXMyMenuCollectionViewCell.h"
#import "AXTopTableViewCell.h"
#import "AXTopCollectionViewCell.h"
#import "AXMidTableViewCell.h"
#import "AXMidCollectionViewCell.h"
#import "UIViewController+HBD.h"
#import "AXOrderViewController.h"
#import "AXEvaluateViewController.h"
#import "AXTkshViewController.h"
#import "AXMySetVC.h"
#import "AXMyGzVC.h"
#import "AXMyScVC.h"
#import "AXMyFbVC.h"
#import "AXMyJfVC.h"
#import "AXMyWdzcVC.h"
#import "AXMyHyzxVC.h"
#import "AXMyWdfxVC.h"
#import "AXMyWdzjVC.h"
#import "AXMyBzkfVC.h"
#import "AXMySqrzVC.h"
#import "AXMyGrzlVC.h"
#import "AXMyJfVC.h"
#import "AXMyKfVC.h"
#import "AXMySrdzWdnzVC.h"
#import "AXMySrdzWdktVC.h"
#import "AXMySrdzWdJsVC.h"
#import "ConfirmOrderViewController.h"
#import "CompanyAboutViewController.h"
#import "MyDiagnosisViewController.h"

#import "MySchemeViewController.h"
#import "GrabDiagnoseViewController.h"
#import "MakeSchemeViewController.h"
#import "ChinaPetroleumMachineryViewController.h"
#import "MyPropertyViewController.h"
#import "CropIntroduceViewController.h"

#import "AXMySrdzWdzwVC.h"
#import "BaseSourceViewController.h"
#import "StoreViewController.h"

#import "BusinessManageViewController.h"
#import "EvaluateStatisticsViewController.h"


#import "AXMyActivityVC.h"
#import "OptimizationBaseViewController.h"

#import "WHRPrivateOrderCell.h"

/** 诊断抢单 */
#import "WHRRobOrderListVC.h"

@interface TZHGMyViewController ()<UITableViewDelegate,UITableViewDataSource>

/** headView */
@property (nonatomic ,strong) UIView *headView;
/** 用户图像 */
@property (nonatomic ,strong) UIImageView *userImageview;
/** 用户名字 */
@property (nonatomic ,strong) UILabel *userNameLabel;
/**签到 */
@property (nonatomic ,strong) UIButton *signinButton;

@property (nonatomic, strong) UITableView *tableView;
/**定位按钮 */
@property (nonatomic, strong) UIBarButtonItem *dwItem;
/**客服按钮 */
@property (nonatomic, strong) UIBarButtonItem *kfItem;


@end

@implementation TZHGMyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.edgesForExtendedLayout = UIRectEdgeTop;
    /** 导航条 */
    self.hbd_barHidden = YES;
    [self setupNavigationItems];
    //    // 状态栏
    UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, -Hn, Wi, Hs)];
    topView.backgroundColor = [UIColor colorWithHex:0x40cd7d];
    [self.view addSubview:topView];
    [self creatView];
    [self setlayout];
    
    
    self.tableView.tableHeaderView = _headView;
    [_headView setNeedsLayout];
    [_headView layoutIfNeeded];//刷新布局
   
    _headView.frame = CGRectMake(0, NAVIGATION_HEIGHT, [UIScreen mainScreen].bounds.size.width, 200);//headView 的大小
    self.tableView.tableHeaderView = _headView;
    //结束通知
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tongzhi:)name:@"EnterAgriculture" object:nil];

}



- (void)creatView {
    
    _headView = [[UIView alloc]init];
    
    
   
    
    self.userImageview = [[UIImageView alloc]init];
    self.userImageview.userInteractionEnabled = YES;
    /** 图片比例切 */
    self.userImageview.contentMode =UIViewContentModeScaleAspectFill;
    self.userImageview.clipsToBounds=YES;//
    self.userImageview.cornerRadius = 50;
    self.userImageview.image = [UIImage imageNamed:@"xy.jpg"];
    [self.headView addSubview:self.userImageview];
    /** 添加手势 */
    UITapGestureRecognizer *click = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
    [self.userImageview addGestureRecognizer:click];
   
    
    self.signinButton = [[UIButton alloc]init];
    self.signinButton.backgroundColor = [UIColor orangeColor];
    [self.signinButton setTitle:@"签到" forState:UIControlStateNormal];
    [self.signinButton addTarget:self action:@selector(qd:) forControlEvents:UIControlEventTouchUpInside];
    [self.signinButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    self.signinButton.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.headView addSubview:self.signinButton];
    
    /** 用户名字 */
    self.userNameLabel = [[UILabel alloc]init];
    self.userNameLabel.text = @"王家大公子";
    self.userNameLabel.font = FONT_SIXTEEN;
    [self.headView addSubview:self.userNameLabel];
    
    
    self.tableView = [[UITableView alloc]init];
    /** 去掉cell线 */
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
    
    //注册cell
  
    [self.tableView registerClass:[AXTopTableViewCell class] forCellReuseIdentifier:[AXTopTableViewCell reuseID]];
    ;
    [self.tableView registerClass:[AXMidTableViewCell class] forCellReuseIdentifier:[AXMidTableViewCell reuseID]];
    ;
     [self.tableView registerClass:[AXAXMyMenuTableViewCell class] forCellReuseIdentifier:[AXAXMyMenuTableViewCell reuseID]];
     [self.tableView registerClass:[WHRPrivateOrderCell class] forCellReuseIdentifier:[WHRPrivateOrderCell reuseID]];
   
    _headView.frame = CGRectMake(0, NAVIGATION_HEIGHT, SCREEN_WIDTH, 200);
    self.tableView.tableHeaderView = self.headView;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
}

- (void)setlayout {
    self.tableView.sd_layout
    .leftSpaceToView(self.view, 0)
    .topSpaceToView(self.view, Hs)
    .widthIs(Wi)
    .heightIs(Hi-Hs-Htb);
    
    
    /** 用户图像 */
    self.userImageview.sd_layout
    .centerXEqualToView(self.headView)
    .topSpaceToView(self.headView, 20)
    .widthIs(100)
    .heightIs(100);
    self.signinButton.sd_layout
    .leftSpaceToView(self.userImageview, 20)
    .centerYEqualToView(self.userImageview)
    .widthIs(100)
    .heightIs(40);
    self.userNameLabel.sd_layout
    .centerXEqualToView(self.headView)
    .topSpaceToView(self.userImageview, 20)
    .widthIs(100)
    .heightIs(30);
    
    
}

#pragma mark -action

- (void)qd:(UIButton *)btn {
    
    AXMyJfVC *vc = [[AXMyJfVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

/** 图像的点击方法 */
- (void)tap:(UITapGestureRecognizer *)gesture {
    
    AXMyGrzlVC *vc = [[AXMyGrzlVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    
}


//自定义UIBarButtonItem

- (void)setupNavigationItems {
    
    /** 导航条左边的按钮 */
    UIButton *szBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [szBtn setImage:[UIImage imageNamed:@"dhsz"] forState:UIControlStateNormal];
    szBtn.frame = CGRectMake(0, 0, 30, 30);
    [szBtn addTarget:self action:@selector(dwAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc]initWithCustomView:szBtn];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    //客服按钮
    UIButton *kfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [kfBtn setImage:[UIImage imageNamed:@"nhkf"] forState:UIControlStateNormal];
    kfBtn.frame = CGRectMake(0, 0, 30, 30);
    [kfBtn addTarget:self action:@selector(kfAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightItem = [[UIBarButtonItem alloc]initWithCustomView:kfBtn];
    self.navigationItem.rightBarButtonItem = rightItem;

}



#pragma mark - action

/** 设置 */
- (void)dwAction:(UIButton *)btn {
    
    AXMySetVC *vc = [[AXMySetVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    
    
}

/** 客服 */
- (void)kfAction:(UIButton *)btn {
 
//    AXMyKfVC *vc = [[ AXMyKfVC alloc]init];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
    
//    ConfirmOrderViewController *vc = [ConfirmOrderViewController new];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
    
//    CompanyAboutViewController *vc = [CompanyAboutViewController new];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
    
//    CompanyAboutViewController *vc = [CompanyAboutViewController new];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
    
//    MyDiagnosisViewController *vc = [MyDiagnosisViewController new];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
    
//    MySchemeViewController *vc = [MySchemeViewController new];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
    
//    GrabDiagnoseViewController *vc = [GrabDiagnoseViewController new];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
    
//    MakeSchemeViewController *vc = [MakeSchemeViewController new];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
    
    
//    ChinaPetroleumMachineryViewController *vc = [ChinaPetroleumMachineryViewController new];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
    
    
//    CropIntroduceViewController *vc = [CropIntroduceViewController new];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
    
//    BaseSourceViewController *vc = [BaseSourceViewController new];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
    
//    StoreViewController *vc = [StoreViewController new];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
    
    OptimizationBaseViewController *vc = [[OptimizationBaseViewController alloc] initWithNibName:@"OptimizationBaseViewController" bundle:nil];;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];

}





#pragma mark - tableViewDelegate & tableViewDatasorce



//几个分区
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 1;
}

/** cell的高度 */

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        
        return 80;
    }
    if (indexPath.section == 1) {
        
        return 80;
    }
    
    BOOL isEnter = [[NSUserDefaults standardUserDefaults] boolForKey:@"EnterAgriculture"];
    if (isEnter) {
        
        return 510;
    }
    return 235;
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    /** 第一个分区 关注、积分、收藏、发布 */
    if (indexPath.section == 0) {
        AXTopTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXTopTableViewCell  reuseID] forIndexPath:indexPath];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
        cell.tapButtonClickedBlock = ^(NSInteger index) {
            //关注
            if (index == 0) {
                
                AXMyGzVC *vc = [[ AXMyGzVC alloc]init];
                  vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }
            //积分
            else if (index == 1){
                 AXMyJfVC *vc = [[  AXMyJfVC alloc]init];
                  vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }
            //收藏
            else if (index == 2){
                AXMyScVC *vc = [[ AXMyScVC alloc]init];
                  vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }
            //发布
            else if (index == 3){
              
                  AXMyFbVC *vc = [[AXMyFbVC alloc]init];
                  vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
                
            }
            
            
        };
        
        return cell;
    }
    
    /** 全部订单、待付款 、、、、*/
    if (indexPath.section == 1) {
        
        AXMidTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXMidTableViewCell  reuseID] forIndexPath:indexPath];
        [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
     
        cell.tapButtonClickedBlock = ^(NSInteger index) {
            if (index == 0) {
                
                AXOrderViewController *vc = [[ AXOrderViewController alloc]init];
                 vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
            }else if (index == 1) {
                
                AXOrderViewController *vc = [[ AXOrderViewController alloc]init];
                 vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
                
            }else if (index == 2){
                
                AXOrderViewController *vc = [[ AXOrderViewController alloc]init];
                 vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
    
            }
            /** 待评价 */
            else if (index == 3){
                AXEvaluateViewController *vc = [[  AXEvaluateViewController alloc]init];
                 vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
                
            }
            /** 售后退款 */
            else if (index == 4) {
                
                 AXTkshViewController *vc = [[   AXTkshViewController alloc]init];
                 vc.hidesBottomBarWhenPushed = YES;
                [self.navigationController pushViewController:vc animated:YES];
               
            }
            
            
           
        };
        
        return cell;
        

    }
    
    
    /** 第二个分区  我的资产、会员中心、、、、*/
    AXAXMyMenuTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[AXAXMyMenuTableViewCell reuseID] forIndexPath:indexPath];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    //取出是否入驻
    BOOL enter = [[NSUserDefaults standardUserDefaults] boolForKey:@"EnterAgriculture"];
    cell.isShow = enter;
        
        cell.tapButtonClickedBlock = ^(NSInteger index, NSInteger setion) {
            
            if (setion == 0) {
               
                //我的资产
                if (index == 0) {
                    
//                    AXMyWdzcVC *vc = [[AXMyWdzcVC alloc]init];
//                    /** 隐藏tabbar */
//                    vc.hidesBottomBarWhenPushed = YES;
//                    [self.navigationController pushViewController:vc animated:YES];
                    
                    MyPropertyViewController *vc = [[MyPropertyViewController alloc] initWithNibName:@"MyPropertyViewController" bundle:nil];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];

                }
                else if (index == 1){
                    
                    AXMyHyzxVC *vc = [[AXMyHyzxVC alloc]init];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                }
                //我的活动
                else if (index == 2){
                    
                    AXMyActivityVC *vc = [[AXMyActivityVC alloc]init];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                }
                else if (index == 3){
                    AXMyWdzjVC *vc = [[AXMyWdzjVC alloc]init];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                }
                else if (index == 4){
                    AXMyBzkfVC *vc = [[AXMyBzkfVC alloc]init];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                }
                else if (index == 5){
                    
                    AXMySqrzVC *vc = [[AXMySqrzVC alloc]init];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                }
            }
            else if (setion == 1) {
                
                
                //私人订制 我的作物
                 if (index == 0){
                    
                    AXMySrdzWdzwVC *vc = [[AXMySrdzWdzwVC alloc]init];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                     
                     NSLog(@"0");
                }
                
                //我的农资
                else if (index == 1){
                    
                    AXMySrdzWdnzVC *vc = [[AXMySrdzWdnzVC alloc]init];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                    NSLog(@"1");

                }
                //专家诊断
                else if (index == 2){
                    
                    AXMySqrzVC *vc = [[AXMySqrzVC alloc]init];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                    NSLog(@"2");

                }
                //我的课堂
                else if (index == 3){
                    
                    AXMySrdzWdktVC *vc = [[AXMySrdzWdktVC alloc]init];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                    NSLog(@"3");
                }
                //我的技术
                else if (index == 4){
                    
                    AXMySrdzWdJsVC *vc = [[AXMySrdzWdJsVC alloc]init];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                    NSLog(@"4");

                }
                //店铺管理
                else if (index == 5){
                    
                    BusinessManageViewController *vc = [[BusinessManageViewController alloc]init];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                    NSLog(@"5");

                }
                //我的评价
                else if (index == 6){
                    
                    EvaluateStatisticsViewController *vc = [[EvaluateStatisticsViewController alloc]init];
                    vc.hidesBottomBarWhenPushed = YES;
                    [self.navigationController pushViewController:vc animated:YES];
                    NSLog(@"6");

                }
                //农技客服
                
                else if (index == 7){
                    
//                    AXMySqrzVC *vc = [[AXMySqrzVC alloc]init];
//                    vc.hidesBottomBarWhenPushed = YES;
//                    [self.navigationController pushViewController:vc animated:YES];
//                    NSLog(@"7");
                    /** 假跳 */
                    WHRRobOrderListVC *vc = [[WHRRobOrderListVC alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];

                }
                
                else if (index == 9){
                    
                    WHRRobOrderListVC *vc = [[WHRRobOrderListVC alloc]init];
                    [self.navigationController pushViewController:vc animated:YES];
                    
                    NSLog(@"7");
                    
                }
                
                
                
            }
            
            
           
            
            
        };
        
        return cell;
        

    
    
}


- (void)tongzhi:(NSNotification *)sender {
    
    [_tableView reloadData];
}


@end

